const { Page } = require('@playwright/test');

class ReportListPage {
    constructor(page) {
        this.page = page;
    }

    async enter_report_list_page() {
        await this.page.getByRole('link', { name: 'Report' }).click();
        await this.page.getByRole('link', { name: 'Order List', exact: true }).click();
    }

    async search_order_no(orderNo) {
        // UAT选择Order List Tab
        await this.page.getByRole('tab', { name: 'Order List', exact: true }).locator('span').click();
        const orderNoXpath = '//*[@id="order-list-tab"]/div[1]/form/div[1]/div[1]/div[1]/div/div/div/div/input';
        await this.page.locator(orderNoXpath).first().click();
        await this.page.locator(orderNoXpath).first().fill(orderNo);
        await this.page.locator('li').filter({ hasText: orderNo }).click();
        // await this.page.getByText(orderNo).click();
        await this.page.getByRole('button', { name: 'Search' }).click();
        await this.page.waitForTimeout(1000);
    }

    async click_first_order_no(orderNo) {
        const firstRowOrderNoXpath = '//*[@id="pane-myReportTab"]/div/div/div[2]/div[4]/div[2]/table/tbody/tr/td[2]/div/a';
        const text = await this.page.locator(firstRowOrderNoXpath).textContent();
        if (text === orderNo) {
            await this.page.getByRole('cell', { name: `${orderNo}` }).locator('a').first().click();
        } else {
            await this.page.locator('button[name="Search"]').click();
        }
    }

    async search_order_no_batch(orderNo) {
        const orderNoString = orderNo.join('\n');
        await this.page.getByPlaceholder('Please input Order No.(batch)', { exact: true }).first().click();
        await this.page.getByPlaceholder('Please input Order No.(batch)', { exact: true }).first().fill(orderNoString);
        await this.page.getByRole('button', { name: 'Search' }).click();
    }

    async search_TRF_no(trfNo) {
        await this.page.getByPlaceholder('Please input TRF No', { exact: true }).first().click();
        await this.page.getByPlaceholder('Please input TRF No', { exact: true }).first().fill(trfNo);
        await this.page.getByText(trfNo).click();
        await this.page.getByRole('button', { name: 'Search' }).click();
    }

    async click_action_button(trNo) {
        const actionButtonXpath = `//*[@id="pane-myReportTab"]/div/div/div[2]/div[5]/div[2]/table/tbody/tr[${trNo}]/td[21]/div/div/button`;
        await this.page.locator(actionButtonXpath).click();
    }

    async actionDropDown() {
        const dropDownXpath = '/html/body/ul';
        const element = this.page.locator(dropDownXpath);
        if (element) {
            const reject = await this.page.locator(dropDownXpath);
            if (reject) {
                // 原代码此处为空
            }
        }
    }

    async enter_quotation_confirm_date() {
        // Implement the method as needed
    }

    async choose_applicant() {
        // Implement the method as needed
    }
}

module.exports = {
    ReportListPage
};
